package voucher_creator.write;

import voucher_creator.Constants;
import voucher_creator.write.excel.Excel;

public class ListWriter {

	private Excel excel;
	
	public ListWriter() {
		this.excel = new Excel();
	}
	
	public void writeData(String excel_list, String destino, String fecha_salida) {
		excel.writeExcel(excel_list, Constants.SHEET_LIST, 0, Constants.B,
				destino);
		excel.writeExcel(excel_list, Constants.SHEET_LIST, 1, Constants.B,
				fecha_salida);		
	}
	
	public void writeList(String excel_list, String nombre_pasajero, 
			String dni_pasajero, String fecha_nac) {
		
		int position = findPosition(excel_list);
		excel.writeExcel(excel_list, Constants.SHEET_LIST, position, Constants.B,
				nombre_pasajero);
		excel.writeExcel(excel_list, Constants.SHEET_LIST, position, Constants.C,
				dni_pasajero);
		excel.writeExcel(excel_list, Constants.SHEET_LIST, position, Constants.D,
				fecha_nac);
	}

	private int findPosition(String excel_list) {
		
		int row = Constants.FIRST_POSITION;
		String data = excel.readExcel(excel_list, Constants.SHEET_LIST, row, Constants.B);
		
		while(!data.equals("")) {
			row++;
			data = excel.readExcel(excel_list, Constants.SHEET_LIST, row, Constants.B);
		}
		
		return row;
	}
}
